// pages/TopicsModule/topics.js
const app = getApp()
Page({
    data: {
        star_clicked: true,
        all_clicked: true,
        followingBarList: {},   //2.15
        allBarList: {},         //3.3

    },

    onLoad: function (options) {
        var that = this
        that.initFollowingBarList()
        that.initAllBarList()
    },
    onShow: function(){
        var that = this
        that.initFollowingBarList()
    },

    initFollowingBarList(){
        var that = this
        wx.request({
            url: `http://${app.globalData.target}/user/followingBarList`,
            data: {
                currentPage: 1,
                pageSize: 100
            },
            header: {
                "hello-token": wx.getStorageSync("hello-token")
            },
            method: 'GET',
            success: function(res){
                console.log(res)
                that.setData({
                    followingBarList: res.data.result.barList
                })
            },
            fail: function(e) {
                console.log('fail to get barList')
                console.log(e)
            }
        })
    },
    initAllBarList(){
        var that = this
        wx.request({
            url: `http://${app.globalData.target}/bar/getBarsWithPage`,
            data: {
                currentPage: 1,
                pageSize: 200,
                postAmount: 0
            },
            header: {
                "hello-token": wx.getStorageSync("hello-token")
            },
            method: 'GET',
            success: function(res){
                console.log(res)
                that.setData({
                    allBarList: res.data.result
                })
            },
            fail: function(e) {
                console.log('fail to get barList')
                console.log(e)
            }
        })
    },

    clickStar: function(){
        var that = this
        if(that.data.star_clicked == true){
            that.setData({
                star_clicked: false
            })
        }else{
            that.setData({
                star_clicked: true
            })
        }
    },
    clickAll: function(){
        var that = this
        if(that.data.all_clicked == true){
            that.setData({
                all_clicked: false
            })
        }else{
            that.setData({
                all_clicked: true
            })
        }
    },
    goToBar: function(e){
        var that = this
        var barid = e.currentTarget.dataset.barid
        wx.navigateTo({
            url: `../TopicsModule/singleTopic?barid=${barid}`
        })
    }
})